#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "matrixThreeD_utils.h"

// 三维矩阵数乘
double*** matrixMulTD(int *x, int *y, int *z) {
    char continueInput[100];
	
	while (!checkTD(x, y, z)) {
		
	}
	double ***mulMatrix = enterMatrixTD(*x, *y, *z);
	if (mulMatrix == NULL) {
		return NULL;
	}
	// 循环输入
    do{
    	while (getchar() != '\n');
    	//输入并检查数字 
    	double k;
    	printf("请输入与矩阵相乘的一个数：");
    	if (scanf(" %lf", &k) != 1) {
    		printf("输入无效，请重新输入一个整数。\n");
    		while(getchar() != '\n');
    		continue;
		}
		    	
    	for (int i = 0; i < *x; i++) {
            for (int j = 0; j < *y; j++) {
                for (int l = 0; l < *z; l++) {
                    mulMatrix[i][j][l] *= k;
                }
            }
        }
    	
    	printf("------数乘后----------\n");
    	printMatrixTD(mulMatrix, *x, *y, *z);
		
        printf("如果继续相乘请按 y(Y),输入其他值终止,谢谢配合！\n");
		while(getchar() != '\n');
		fgets (continueInput, sizeof(continueInput), stdin);
        continueInput[strcspn(continueInput, "\n")] = 0;
    } while ((continueInput[0] == 'y' || continueInput[0] == 'Y') && continueInput[1] == '\0');
	
    return mulMatrix;
}
